﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication.BLL;

namespace ConsoleApplication
{
    class MainMethod
    {
        static void Main(string[] args)
        {
            /// Samples -   Static Constructor
            //ConsoleApplication.Samples.StaticConstructor.MainMethod();

            /// Configuration
            ReadXml.ReadXmlMain();

            ///  Console input / output
            //ConsoleApp.ConsoleIO();

            ///  intArray
            //intArray.getLinearArray();
            //intArray.get2Array();
            //intArray.getArrayInArray();

            /// Delegate
            //Delegate.printMaxValue();       //  Use the processDelegate - process

            /// Class
            //BaseMathObjects.MainClassMethod();
            //Point.MainClassMethod();

            /// Abstract Class & Interface
            //BaseMathObjects.MainClassMethod();

            ///     Array / ArrayList
            //myArrayList.ShowArray();

            ///     Operator Overload
            //Point_BLL.showPoint();

            ///     List
            //List_BLL.showList();

            ///     Read File
            //ReadFiles.ReadFileNames();
            //ReadFiles.ReadFileContentTest();
            //ReadFiles.ReadFileContent();

            //BaseClass.getString();
            //DerivedClassExample();

            /// Generics
            //Generics.MainMethod();
            //myList<int, int>.StaticCompare(1, 2);

            

            //Console.ReadKey();

        }

        /// <summary>
        /// 类和接口的多态
        /// </summary>
        private static void DerivedClassExample()
        {
            Console.WriteLine("\n----------Base Class instance bc1, initialize with BaseClass()");
            BaseClass bc1 = new BaseClass();
            Console.WriteLine(bc1.strPublic);                    //  strPublicBase
            Console.WriteLine(bc1.getPublicString());      //  strPublicBase

            Console.WriteLine("\n----------Base Class instance bc2, initialize with DerivedClass()");
            BaseClass bc2 = new DerivedClass();
            Console.WriteLine(bc2.strPublic);                    //  strPublicBase
            Console.WriteLine(bc2.getPublicString());      //  strPublicBase
            Console.WriteLine(((DerivedClass)bc2).DerivedClassMethod());      //  strPrivateDerived

            Console.WriteLine("\n----------Derived Class instance dc1, initialize with DerivedClass()");
            DerivedClass dc1 = new DerivedClass();
            Console.WriteLine(dc1.strPublic);                                 //  strPublicDerived
            Console.WriteLine(dc1.getPublicString());                   //  strPublicDerived
            Console.WriteLine(dc1.DerivedClassMethod());        //  strPrivateDerived

            Console.WriteLine("\n----------BaseClass bc3 = dc1;");
            BaseClass bc3 = dc1;
            Console.WriteLine(bc3.strPublic);                                                            //  strPublicBase
            Console.WriteLine(bc3.getPublicString());                                              //  strPublicBase
            Console.WriteLine(((DerivedClass)bc3).getPublicString());                 //  strPublicDerived
            Console.WriteLine(((DerivedClass)bc3).DerivedClassMethod());      //  strPrivateDerived

            Console.WriteLine("\n----------IBaseInterface");
            IBaseInterface IBIF = new BaseClass();
            IBaseInterface IDIF = new DerivedClass();
            Console.WriteLine(IBIF.getPublicString());                                             //  strPublicBase
            Console.WriteLine(((BaseClass)IBIF).getPublicString());                     //  strPublicBase
            Console.WriteLine(IDIF.getPublicString());                                             //  strPublicDerived
            Console.WriteLine(((DerivedClass)IDIF).DerivedClassMethod());      //  strPrivateDerived

            Console.WriteLine("\n----------DerivedClass dc2 = (DerivedClass)bc1;");
            DerivedClass dc2 = (DerivedClass)bc2;
            //DerivedClass dc2 = (DerivedClass)bc1;       //*  InvalidCastException -> Unable to cast object of type 'ConsoleApplication.BaseClass' to type 'ConsoleApplication.DerivedClass'.
            Console.WriteLine(dc2.strPublic);                                 //  strPublicDerived
            Console.WriteLine(dc2.getPublicString());                   //  strPublicDerived
            Console.WriteLine(dc2.DerivedClassMethod());        //  strPrivateDerived

            Console.ReadKey();

        }
        private void DerivedClassExample2() { }

    }
}
